jslib.$_$('jslib.plugin.DDList',{
	options : {
		cont : '.ddlistone',
		bar : '.spa',
		button : '.selectArrow',
		list_cont : '.selectCont',
		list : 'a',
		def : 0
	},
	initialize : function(){
		var opt = this.options;
		var thisname = this.thisname = opt.thisname;
		this.Container = document.getElement(opt.cont);
		this.Bar = this.Container.getElement(opt.bar);
		this.Button = this.Container.getElement(opt.button);
		this.ListCont = this.Container.getElement(opt.list_cont);
		this.List = this.ListCont.getElements(opt.list);
		
		this.setValue(opt.def);
		
		this.timer = null;
		this.Bar.addEvent('click', this.onButtonClick.bind(this));
		this.Button.addEvent('click', this.onButtonClick.bind(this));
		this.Button.addEvent('mouseout', this.onMouseOut.bind(this));
		this.List.each(function(item, index){
			item.addEvent('click',this.onItemClick.bind(this));
			item.addEvent('mouseover',this.onMouseOver.bind(this));
			item.addEvent('mouseout',this.onMouseOut.bind(this));
		}.bind(this));
		
		
	},
	onButtonClick : function(e){
		if(this.ListCont.getStyle('display') === 'none')
			this.showList();
		else
			this.hideList();
	},
	onItemClick : function(e){
		e = e || window.event;
		tar =  e.target || e.srcElement;
		var i = this.List.indexOf(tar);
		
		this.setValue(i);
		this.hideList();
	},
	onMouseOver : function(e){
		if(this.timer){
			$clear(this.timer);
			this.timer = null;
		}
		
	},
	onMouseOut : function(e){
		this.timer = this.hideList.delay(300, this);
	},
	setValue : function(index){
		this.List.each(function(_item, _index){
			if(index === _index){
					_item.getParent('li').addClass('set');
			}
			else{
					_item.getParent('li').removeClass('set');
			}
		});
		var item = this.List[index];
		this.currentValue = item.get('p-value');
		this.Bar.set('text', item.get('text'));

		this.Bar.fireEvent('changed');
	},
	showList : function(){
		this.ListCont.setStyle('display', 'block');
	},
	hideList : function(){
		this.ListCont.setStyle('display', 'none');
	}
	
});